package es.ats.codington.web.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import es.ats.codington.festival.domain.Visitor;
import es.ats.codington.festival.services.VisitorService;

/**
 * Servlet implementation class InfVisitorServlet
 */
@WebServlet("/InfVisitorServlet")
public class InfVisitorServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InfVisitorServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String visitorName=null;
		Visitor visitor = new Visitor();
		VisitorService visitorService = new VisitorService();
		Cookie cookie= null;
		Cookie[] cookies=request.getCookies();
		if(cookies!=null){
			for(int i=0; i<cookies.length; i++){
				cookie=cookies[i];
				if(cookie.getName().compareTo("user")==0)
				visitorName=cookie.getValue();
			}
		}
		visitor = visitorService.getVisitorService(visitorName);
		request.setAttribute("visitor", visitor);
		RequestDispatcher rd= request.getRequestDispatcher("editUser.jsp");
		rd.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}
}
